<template>
  <a-layout id="components-layout-demo-custom-trigger" class="wrapImg" style="height: auto;">
    <a-layout-header class="headerWrap">
      <!-- <div class="logoName">
        <img src="~@/assets/gateway/Frame 8.png" alt="" srcset="" />
      </div> -->
  <div class="logoName">
        <img style="margin-right: 5px; width: 40px" src="~@/assets/logo.png" />
        中建八局西南公司
      </div>
      <div class="userHeader">
        
        <AvatarDown />
      </div>
    </a-layout-header>
  </a-layout>
</template>
<script>
import { mapState } from 'vuex'
// import MenuBasic from '@/layouts/MenuBasicV3'
// import MultiTab2 from '@/components/MultiTab2'
import AvatarDown from './avatarDown'
import MessageIcon from '@/layouts/messageIcon.vue'
// import PostSelect from '@/layouts/PostSelect.vue'
import setting from '@/config/defaultSettings'

export default {
  data() {
    return {
      collapsed: false,
      noCache: ['materialMasterPlanIndex'],
      popoverVisible: false,
      timer: 0,
      iframeArr: [],
      componentsArr: [],
      title: setting.title,
      rootActive: 'projectManage'
    }
  },
  created() {
    // 缓存iframe路由
    let routes = this.$store.getters.addRouters.find((i) => i.path === '/')?.children?.find((i) => i.name === 'jixiao')?.children
    this.getComponentsArr(routes)
    this.isOpenIframePage()
  },
  watch: {
    $route() {
      this.isOpenIframePage()
    }
  },
  components: {
    // MultiTab2,
    AvatarDown,
    // MenuBasic,
    MessageIcon,
    // PostSelect
  },
  beforeRouteEnter(to, from, next) {
    next((vm) => {
      if (from.path === '/login') {
        vm.popoverVisible = true
        vm.timer = setTimeout(() => {
          vm.popoverVisible = false
          clearTimeout(vm.timer)
        }, 10000)
      }
    })
  },
  methods: {
    // 扁平化路由
    flatRouters(list) {
      let routers = []
      function getList(e) {
        for (let item of e) {
          routers.push(item)
          if (item.children?.length) {
            getList(item.children)
          }
        }
      }
      getList(list)
      return routers
    },
    // 是否为iframe页面
    isOpenIframePage() {
      const target = this.componentsArr.find((item) => {
        return item.path === this.$route.path
      })

      if (target && !target.hasOpen) {
        target.hasOpen = true
      }
    },
    // 筛选需要缓存的iframe页面
    getComponentsArr(routes) {
      routes && routes.forEach((it) => {
        if (it.iframeComponent) {
          const name = it.name || it.path.replace('/', '')

          this.componentsArr.push({
            name: name,

            path: it.path,

            hasOpen: false,

            component: it.iframeComponent
          })
        }

        if (it.children && it.children.length > 0) {
          this.getComponentsArr(it.children)
        }
      })
    },
    beforeEnter(el) {
      this.$nextTick(() => {
        el.parentNode && (el.parentNode.style.overflow = 'hidden')
      })
    },
    afterEnter(el) {
      this.$nextTick(() => {
        el.parentNode && (el.parentNode.style.overflow = 'auto')
      })
    },
    switchSecondaryMenu(showSecondaryMenu) {
      this.collapsed = !showSecondaryMenu
    },
    rootMenuChange(val){
      this.rootActive = val
    }
  },
  mounted(){
    console.log(this.rooterMenus)
  },
  computed: {
    ...mapState({
      // 动态主路由
      mainMenu: (state) => state.permission.addRouters,
      rooterMenus: state => state.user.rooterMenus,
    }),
    menuWidth() {
      return this.collapsed ? '80px' : '280px'
    },
    style() {
      return {
        minWidth: '1200px',
        height: 'auto',
        overflowY: 'auto',
        overflowX: 'hidden'
      }
    },
    // 懒加载缓存的iframe页面
    hasOpenComponentsArr() {
      return this.componentsArr.filter((item) => item.hasOpen && this.$store.state.tabInfo.pathMap.some(i=> i.path === item.path))
    }
  }
}
</script>
<style lang="less" scoped>
// #components-layout-demo-custom-trigger.wrapImg {
//   background: url('../../src/assets/rbg.jpg') no-repeat top center;
//   background-size: cover;
// }

#components-layout-demo-custom-trigger {
  .logoName{
    padding: 0 20px;
    font-size: 18px;
    color: white;
    font-weight: bold;
    cursor: default;
  }
  .trigger {
    font-size: 18px;
    line-height: 64px;
    padding: 0 24px;
    cursor: pointer;
    transition: color 0.3s;
  }

  .trigger:hover {
    color: #1890ff;
  }

  .logo {
    height: 32px;
    background: rgba(255, 255, 255, 0.2);
    margin: 16px;
  }

  .main {
    position: relative;
    height: 100%;
    width: 100%;
    overflow: hidden;

    .ant-pro-page-header-wrap {
      .ant-pro-page-header-wrap-page-header-warp {
        background: none;

        .ant-pro-grid-content {
          .ant-page-header.has-breadcrumb {
            padding: 12px 10px;

            .ant-breadcrumb > span:last-child {
              color: #333333;
            }
          }
        }
      }
    }

    .ant-pro-page-header-wrap > .ant-pro-grid-content {
      /*position: relative;*/
      /*height: 100%;*/
      /*width: 100%;*/
      /*overflow: auto;*/

      .ant-pro-page-header-wrap-children-content {
        padding: 0 10px;
        margin: 0;
      }
    }
  }

  .ant-tabs-bar.ant-tabs-top-bar.ant-tabs-card-bar {
    background: none !important;
    border: none !important;
    /*padding-left: 10px!important;*/
    padding-left: 0px !important;
    overflow: hidden;
  }

  .headerWrap {
    position: relative;
    background: #0089ca;
    padding: 0;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .ant-tabs-bar{
      border-bottom: none;
    }
    .ant-tabs-nav-container{
      line-height: 2;
      color: white;
    }
    .ant-tabs-tab-active{
      color: white;
    }
    .ant-tabs-ink-bar{
      background-color: white;
      height: 3px;
      bottom: 2px;
      border-radius: 2px;
    }
    .userHeader {
      display: flex;
      justify-content: flex-end;
      width: 400px;
      padding-right: 20px;
      color: #ffffff;
      text-align: center;
    }

    .ant-pro-multi-tab {
      position: absolute;
      bottom: 0;
      left: 0;
      width: 100%;
      /*margin: -37px 0 0;*/
      z-index: 100;
      background: none;

      .ant-tabs-nav-container {
        height: 48px;

        .ant-tabs-nav-wrap {
          .ant-tabs-nav-scroll {
            padding: 0 10px;
          }
        }
      }

      .ant-pro-multi-tab-wrapper {
        padding-left: 0;

        .ant-tabs-tab-prev,
        .ant-tabs-tab-next {
          background-color: #ffffff;
          border-right: 1px solid #e8e8e8;
          border-left: 1px solid #e8e8e8;
          border-top-left-radius: 4px;
          border-top-right-radius: 4px;
        }

        .ant-tabs-nav-wrap {
          .ant-tabs-tab {
            height: 48px;
            line-height: 48px;
            background: none;
            color: #ffffff;
            border: none;
            background: rgba(0, 0, 0, 0.4);
            padding-left: 44px;
            padding-right: 44px;
            border-radius: 4px 4px 0px 0px;
          }

          .ant-tabs-tab.ant-tabs-tab-active {
            background: #ffffff;
            color: #1890ff;
            border-color: #e8e8e8;
            border-bottom: 1px solid #ffffff;
            border-top-left-radius: 4px;
            border-top-right-radius: 4px;
          }
        }
      }
    }
  }
}
  .logoName {
    padding: 0 20px;
    font-size: 18px;
    color: white;
    font-weight: bold;
    cursor: default;
  }
</style>
